package com.whw.fy.controller;

import com.whw.fy.entity.Excute;
import com.whw.fy.entity.Message;
import com.whw.fy.service.ExcuteService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.text.ParseException;
import java.text.SimpleDateFormat;

@Api(tags = "教学计划执行模块")
@RestController
@RequestMapping("/api/excute")
public class ExcuteController {
    @Resource
    private ExcuteService excuteService;

    @ApiOperation(value = "添加教学执行记录")
    @PostMapping("/one")
    public Message insert(Excute excute) throws ParseException {
        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        if (excute.getExcuteStarttimeToString()!=null)
            excute.setExcuteStarttime(simpleDateFormat.parse(excute.getExcuteStarttimeToString()));
        return excuteService.insertSelective(excute);
    }

    @ApiOperation(value = "删除教学执行记录")
    @DeleteMapping("/")
    public Message delete(Integer excuteId) {
        return excuteService.deleteByPrimaryKey(excuteId);
    }

    @ApiOperation(value = "修改教学执行记录")
    @PutMapping("/")
    public Message update(Excute excute) throws ParseException {
        return excuteService.updateByPrimaryKeySelective(excute);
    }

    @ApiOperation(value = "获取所有教学执行记录")
    @GetMapping("/all")
    public Message selectAll(){
        return excuteService.selectAll();
    }

    @ApiOperation(value = "根据教学计划id获取教学计划")
    @GetMapping("/one")
    public Message selectByPrimaryKey(Integer excuteId){
        return excuteService.selectByPrimaryKey(excuteId);
    }


}
